package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ReceiptOrderDetailMapper;
import com.ruoyi.system.domain.ReceiptOrderDetail;
import com.ruoyi.system.service.IReceiptOrderDetailService;

/**
 * 入库单详情Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-12
 */
@Service
public class ReceiptOrderDetailServiceImpl implements IReceiptOrderDetailService 
{
    @Autowired
    private ReceiptOrderDetailMapper receiptOrderDetailMapper;

    /**
     * 查询入库单详情
     * 
     * @param id 入库单详情主键
     * @return 入库单详情
     */
    @Override
    public ReceiptOrderDetail selectReceiptOrderDetailById(Long id)
    {
        return receiptOrderDetailMapper.selectReceiptOrderDetailById(id);
    }

    @Override
    public List<ReceiptOrderDetail> selectReceiptOrderDetailByStatus(Long id) {
        return receiptOrderDetailMapper.selectReceiptOrderDetailByStatus(id);
    }

    @Override
    public List<ReceiptOrderDetail> selectReceiptOrderDetail(Long id) {
        return receiptOrderDetailMapper.selectReceiptOrderDetail(id);
    }

    @Override
    public int updateDetail(ReceiptOrderDetail receiptOrderDetail) {
        return receiptOrderDetailMapper.updateDetail(receiptOrderDetail);
    }

    /**
     * 查询入库单详情列表
     * 
     * @param receiptOrderDetail 入库单详情
     * @return 入库单详情
     */
    @Override
    public List<ReceiptOrderDetail> selectReceiptOrderDetailList(ReceiptOrderDetail receiptOrderDetail)
    {
        return receiptOrderDetailMapper.selectReceiptOrderDetailList(receiptOrderDetail);
    }

    @Override
    public List<Map<String,Object>> selectReceiptOrderIdList(Long id) {
        return receiptOrderDetailMapper.selectReceiptOrderIdList(id);
    }

    /**
     * 新增入库单详情
     * 
     * @param receiptOrderDetail 入库单详情
     * @return 结果
     */
    @Override
    public int insertReceiptOrderDetail(ReceiptOrderDetail receiptOrderDetail)
    {
        receiptOrderDetail.setCreateTime(DateUtils.getNowDate());
        return receiptOrderDetailMapper.insertReceiptOrderDetail(receiptOrderDetail);
    }

    /**
     * 修改入库单详情
     * 
     * @param receiptOrderDetail 入库单详情
     * @return 结果
     */
    @Override
    public int updateReceiptOrderDetail(ReceiptOrderDetail receiptOrderDetail)
    {
        ReceiptOrderDetail detail = receiptOrderDetailMapper.ReceiptOrderDetailByIdByitem(receiptOrderDetail);
        if (detail!=null){
            receiptOrderDetail.setUpdateTime(DateUtils.getNowDate());
            return receiptOrderDetailMapper.ReceiptOrderDetail(receiptOrderDetail);
        }else {
            receiptOrderDetail.setCreateTime(DateUtils.getNowDate());
            return receiptOrderDetailMapper.insertReceiptOrderDetail(receiptOrderDetail);
        }
    }

    /**
     * 批量删除入库单详情
     * 
     * @param ids 需要删除的入库单详情主键
     * @return 结果
     */
    @Override
    public int deleteReceiptOrderDetailByIds(Long[] ids)
    {
        return receiptOrderDetailMapper.deleteReceiptOrderDetailByIds(ids);
    }

    /**
     * 删除入库单详情信息
     * 
     * @param id 入库单详情主键
     * @return 结果
     */
    @Override
    public int deleteReceiptOrderDetailById(Long id)
    {
        return receiptOrderDetailMapper.deleteReceiptOrderDetailById(id);
    }
}
